import { FrameTimer } from "../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../com/gengine/core/frame/TimerType";
import { LayerManager } from "./LayerManager";
import { RollRadioItem } from "../view/msgbroad/RollRadioItem";
import { ObjectPool } from "../../../com/gengine/utils/pools/ObjectPool";
import { RollRadioInfo } from "../model/RollRadioInfo";
import { Global } from "../../../com/gengine/global/Global";
type int = number;
//class MsgRollRadioImpl
    
    export  class MsgRollRadioImpl
    {
        constructor()
        {
            
            this._msgs = [];
            return;
        }

        /* internal  */startRollRadio(): void
        {
            if (!this._timer) 
            {
                this._timer = new FrameTimer(1);
            }
            this._timer.addListener(TimerType.ENTERFRAME, this.frameScript);
            if (!this._timer.running) 
            {
                this._timer.reset();
                this._timer.start();
            }
            return;
        }

        /* internal  */stopRollRadio(): void
        {
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
                this._timer.dispose();
                this._timer.isDelete = false;
            }
            return;
        }

        /* internal  */hideRollRadio(): void
        {
            if (this._item) 
            {
                this._item.dispose();
                if (this._item.parent) 
                {
                    this._item.parent.removeChild(this._item);
                }
            }
            return;
        }

        /* internal  */showRollRadio(): void
        {
            if (this._item) 
            {
                LayerManager.msgTipLayer.addChild(this._item);
                this.stageResize();
            }
            return;
        }

        /* internal  */frameScript(arg1: FrameTimer): void
        {
            if (this._msgs.length > 0) 
            {
                this._hideTimer = 0;
                if (this._item) 
                {
                    if (this._item.running) 
                    {
                        this._item.frameScript();
                    }
                    else if (this._item.hasEnd && this._msgs[0] == this._item.info) 
                    {
                        this._msgs.shift();
                        if (this._msgs.length > 0) 
                        {
                            this._item.updateData(this._msgs[0]);
                            this.showRollRadio();
                        }
                    }
                    else if (this._countTimer >= this._countTotal) 
                    {
                        this._countTimer = 0;
                        this._item.updateData(this._msgs[0]);
                        this.showRollRadio();
                    }
                    else 
                    {
                        var loc1;
                        var loc2=((loc1 = this)._countTimer + 1);
                        loc1._countTimer = loc2;
                    }
                }
                else 
                {
                    this._item = new RollRadioItem();
                    this._item.updateData(this._msgs[0]);
                    this.showRollRadio();
                }
            }
            else if (this._hideTimer >= this._hideTotal) 
            {
                this.hide();
            }
            else 
            {
                loc2 = ((loc1 = this)._hideTimer + 1);
                loc1._hideTimer = loc2;
            }
            return;
        }

        public showMsg(arg1: string, arg2: int, arg3: int): void
        {
            var loc1;
            (loc1 = ObjectPool.getObject(RollRadioInfo)).str = arg1;
            loc1.totalCount = arg2;
            loc1.speed = arg3;
            this._msgs.push(loc1);
            this.startRollRadio();
            return;
        }

        public stageResize(): void
        {
            if (this._item && this._item.parent) 
            {
                this._item.x = (Global.stage.stageWidth - this._item.width) / 2;
                this._item.y = 55;
            }
            return;
        }

        public hide(): void
        {
            this.stopRollRadio();
            this.hideRollRadio();
            return;
        }

        /* internal */ /* const */_hideTotal: int=60;

        /* internal */ /* const */_countTotal: int=12;

        /* internal */ /* var */_msgs: Array<any>;

        /* internal */ /* var */_timer: FrameTimer;

        /* internal */ /* var */_item: RollRadioItem;

        /* internal */ /* var */_hideTimer: int;

        /* internal */ /* var */_countTimer: int;
    }
